import { Router } from 'express'

const router = Router()

// 内存模拟轮播图数据
let carousels = [
  { id: 1, title: '示例轮播图', image: '', status: 1, position: '首页', sort: 1 }
]

// 获取轮播图列表（支持分页、标题、状态、位置筛选）
router.get('/', (req, res) => {
  const { page = 1, pageSize = 10, title = '', status, position } = req.query
  let filtered = carousels.filter(c =>
    (!title || c.title.includes(title as string)) &&
    (status === undefined || c.status == Number(status)) &&
    (!position || c.position === position)
  )
  const start = (Number(page) - 1) * Number(pageSize)
  const end = start + Number(pageSize)
  res.json({
    total: filtered.length,
    items: filtered.slice(start, end)
  })
})

export default router 